import Vue from 'vue'
import Vuex from 'vuex'


Vue.use(Vuex)

export default new Vuex.Store({
  namespace: true,
  // 相当于组件中的data  组件中获取使用this.$store.state.nickName
  state: {
    user: "",
    token:""
  },
  getters: {},
  mutations: {
    // changeNickName(state){  //不传参
    // 传参
    getUser(state, name) {
      console.log(state,name,999999);
      this.state.user = name ? name : "";
    },
    getToken(state, name){
      console.log(state,name,8888);
      this.state.token = name ? name : "";
    }
  },
  // actions专门用来处理异步，实际修改状态值的依然是mutations
  // 在组件内如何调用？this.$store.dispatch('testActions')
  actions: {
    userActions(context,params) {
      context.commit('getUser',params)
    },
    tokenActions(context,params){
      context.commit('getToken',params)
    }
  },
  modules: {},
})